<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    function fn1() {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          console.log('fn1 -----> 2s完成');
          resolve();
        }, 2000);
      });
    }
    function fn2() {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          console.log('fn2 -----> 2s完成');
          resolve();
        }, 2000);
      });
    }
    function fn3() {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          console.log('fn3 -----> 2s完成');
          resolve();
        }, 2000);
      });
    }
    console.time();
    /* 
        Promise.all,可以一次发送所有的请求，请求都回来之后，才进入回调
        可以避免每一个请求都在等待的问题
        语法： Promise.all([promise1,promise2,promiseN]).then()
    */
    Promise.all([fn1(), fn2(), fn3()]).then(() => {
      console.log('所有请求都完成了 -----> ');
      console.timeEnd();
    });
  </script>
</html>
